﻿using System;
using ZFramework.Runtime;

namespace ZGame
{
    public abstract class FguiUIFormLogicLogicEx : FGuiUIFormLogicBase
    {
        private EventSubscriber eventSubscriber;

        public void Close()
        {
            UnSubscribeAll();
            if (eventSubscriber != null)
            {
                ReferencePool.Release(eventSubscriber);
                eventSubscriber = null;
            }

            GameEntry.uiMgr.CloseUI(UiForm.SerialId);
        }
        
        protected void Subscribe(int id, EventHandler<GameEventArgs> handler)
        {
            if (eventSubscriber == null)
                eventSubscriber = EventSubscriber.Create(this);

            eventSubscriber.Subscribe(id, handler);
        }

        protected void UnSubscribe(int id, EventHandler<GameEventArgs> handler)
        {
            if (eventSubscriber != null)
                eventSubscriber.UnSubscribe(id, handler);
        }

        protected void UnSubscribeAll()
        {
            if (eventSubscriber != null)
                eventSubscriber.UnSubscribeAll();
        }

        protected void SubscribeAll()
        {
            
        }
    }
}